<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .pre{
            background-color: green;
            color: white;
        }
        .next{
            background-color: red;
            color: white;
        }
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <input type="hidden" readonly id="receiveMember" name="receiveMember" class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">PO:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceNo"  name="produceNo" class="form-control">
                        </div>

                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select  name="flag" id="flag" class="form-control">
                                <option value="">请选择状态</option>
                                <option value="0">进行中</option>
                                <option value="1">已结束</option>
                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>

                </form>
            </div>

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/produce/node/findByCnd.do?flag=0"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload'}){}%>
<script>

    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: 'PO',
                    field: 'produceNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'produceSupplierName',
                    title: '供应商',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '下单时间',
                    align: 'center',
                    formatter:function (v,r){
                        return v.substr(0,10);
                    }
                },
                {
                    title: '面料来样(预计)',
                    field: 'produceNodeOneExpectTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '面料来样(实际)',
                    field: 'produceNodeOneRealTime',
                    align: 'center',
                    valign: 'middle',
                    cellStyle: function (v, r) {
                        if (r.produceNodeOneExpectTime != null && r.produceNodeOneExpectTime != '' && (r.produceNodeOneRealTime=='' || r.produceNodeOneRealTime==null)) {
                            if (DateDiff(r.produceNodeOneExpectTime) >= 1) {
                                return {
                                    classes: 'next'
                                }
                            } else if (DateDiff(r.produceNodeOneExpectTime) >${produce_node_one_expect_time}) {
                                return {
                                    classes: 'pre'
                                }
                            }else{
                                return {

                                }
                            }
                        }else{
                            return {

                            }
                        }
                    }
                },
                {
                    title: '上生产线(预计)',
                    field: 'produceNodeTwoExpectTime',
                    align: 'center'
                },
                {
                    title: '上生产线(实际)',
                    field: 'produceNodeTwoRealTime',
                    align: 'center',
                    cellStyle: function (v, r) {
                        if (r.produceNodeTwoExpectTime != null && r.produceNodeTwoExpectTime != '' && (r.produceNodeTwoRealTime=='' || r.produceNodeTwoRealTime==null)) {
                            if (DateDiff(r.produceNodeTwoExpectTime) >= 1) {
                                return {
                                    classes: 'next'
                                }
                            } else if (DateDiff(r.produceNodeTwoExpectTime) >${produce_node_one_expect_time}) {
                                return {
                                    classes: 'pre'
                                }
                            }else{
                                return {

                                }
                            }
                        }else{
                            return {

                            }
                        }
                    }
                },
                {
                    title: '后道整理(预计)',
                    field: 'produceNodeThreeExpectTime',
                    align: 'center'
                },
                {
                    title: '后道整理(实际)',
                    field: 'produceNodeThreeRealTime',
                    align: 'center',
                    cellStyle: function (v, r) {
                        if (r.produceNodeThreeExpectTime != null && r.produceNodeThreeExpectTime != '' && (r.produceNodeThreeRealTime=='' || r.produceNodeThreeRealTime==null)) {
                            if (DateDiff(r.produceNodeThreeExpectTime) >= 1) {
                                return {
                                    classes: 'next'
                                }
                            } else if (DateDiff(r.produceNodeThreeExpectTime) >${produce_node_one_expect_time}) {
                                return {
                                    classes: 'pre'
                                }
                            }else{
                                return {

                                }
                            }
                        }else{
                            return {

                            }
                        }
                    }
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.edit-btn').on('click',function(){//新增
                    var id=$(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/supply/produce/node/editPage.do?id='+id, 'yes']
                    });
                });

                $('.edit-real-btn').on('click',function(){//新增
                    var id=$(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/supply/produce/node/editRealPage.do?id='+id, 'yes']
                    });
                });

                $('.del-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.confirm('确定要删除当前？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/bill/delete.do',{id: id},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
            }
        });

        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/produce/node/findByCnd.do?'+$('#search-form').serialize() });
        });
    });

    // 操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-btn btn btn-xs btn-info" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i> 修改预计</button>&nbsp;';
        content+= '<button class="edit-real-btn btn btn-xs btn-info" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i> 修改实际</button>';
        content += '<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i>  </button>';
        return content;
    }

    function DateDiff(start) {

        var end=new Date();
        var sdate = new Date(start);
        var now = new Date(end);
        var days = now.getTime() - sdate.getTime();
        var day = parseInt(days / (1000 * 60 * 60 * 24));

        return day;
    }
</script>
</body>
</html>
